package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.vo.InOutWarehouseOrderVo;
import com.sevattal.service.leaves.entity.vo.InspectionArrivalOrderVo;
import com.sevattal.service.leaves.service.InOutWarehouseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  出入库主表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "出入库管理")
@RestController
@RequestMapping("/admin/leaves/in-out-warehouse-order")
public class InOutWarehouseOrderController {


    @Autowired
    private InOutWarehouseOrderService inOutService;


    @ApiOperation("新建出入库单")
    @PostMapping("createInOutOrder")
    public R createInOutOrder(@ApiParam(value = "出入库单对象",required = true) @RequestBody InOutWarehouseOrderVo inOutOrderVo){
        boolean result = inOutService.createInOutOrder(inOutOrderVo);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改出入库单")
    @PutMapping("updateInOutOrder")
    public R updateInOutOrder(@ApiParam(value = "出入库到货单对象",required = true) @RequestBody InOutWarehouseOrderVo inOutOrderVo) {
        boolean result = inOutService.updateInOutOrder(inOutOrderVo);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除出入库单")
    @DeleteMapping("deleteInOutOrder/{id}")
    public R deleteInOutOrder(@ApiParam(value = "出入库单ID",required = true) @PathVariable String id) {
        boolean result = inOutService.deleteInOutOrder(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }


    @ApiOperation("获取出入库信息")
    @PostMapping("getInOutOrderList/{page}/{limit}")
    public R getInOutOrderList( @ApiParam(value="页码",required= true) @PathVariable Long page,
                                @ApiParam(value="每页记录数",required = true) @PathVariable Long limit,
                                @ApiParam(value = "出入库单对象",required =  true) @RequestBody InOutWarehouseOrderVo inOutOrderVo){
        List<InOutWarehouseOrderVo> inOutOrderVoList = inOutService.getInOutOrderList(page,limit,inOutOrderVo);
        return R.ok().data("inOutOrderVoList",inOutOrderVoList);
    }

    @ApiOperation("确认出入库")
    @PostMapping("confirmInOutOrder/{id}")
    public R confirmInOutOrder(@ApiParam(value = "确认出入库订单id",required = true) @PathVariable String id ){
        boolean result = inOutService.confirmInOutOrder(id);
        if (result) {
            return R.ok().message("确认成功");
        }else{
            return R.error().message("确认失败");
        }
    }

}

